package com.heima.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.admin.mapper.AdSensitiveMapper;
import com.heima.admin.service.AdWmSensitiveService;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.SensitiveDto;
import com.heima.model.wemedia.pojos.WmSensitive;
import org.springframework.stereotype.Service;

@Service
public class AdWmSensitiveServiceImpl extends ServiceImpl<AdSensitiveMapper, WmSensitive> implements AdWmSensitiveService {
    /**
     * 获取敏感词列表
     * @param sensitiveDto
     * @return
     */
    @Override
    public ResponseResult getList(SensitiveDto sensitiveDto) {
        //分页
        Page<WmSensitive> sensitivePage=new Page<>(sensitiveDto.getPage(),sensitiveDto.getSize());

        LambdaQueryWrapper<WmSensitive> lqw=new LambdaQueryWrapper<>();
        //模糊查询
        if (sensitiveDto.getName()!=null){
            lqw.like(WmSensitive::getSensitives,sensitiveDto.getName());
        }
        //排序 创建时间倒序
        lqw.orderByDesc(WmSensitive::getCreatedTime);
        Page<WmSensitive> page = page(sensitivePage, lqw);
        PageResponseResult pageResponseResult=
                new PageResponseResult((int) page.getCurrent(),(int)page.getSize(),(int)page.getTotal());
        pageResponseResult.setData(page.getRecords());
        return pageResponseResult;
    }
}
